package com.example.testbroadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class MyBroadcastReceiver2 extends BroadcastReceiver {
    public MyBroadcastReceiver2() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        Log.d("main", String.format("receive %s", action));

        if (action.indexOf("MY_BROADCAST") != -1) {
            Toast.makeText(context, "收到广播", Toast.LENGTH_SHORT).show();
        } else if (action.indexOf("CONNECTIVITY_CHANGE") != -1) {
            Toast.makeText(context, "网络状态发生改变", Toast.LENGTH_SHORT).show();
        }
    }
}
